#!/bin/sh

DATE="${1}"
DIRECTORY=/data/backups
REPORT="${2}/backup_${DATE}.txt"

INDEX=0
FIRSTBACKUPNODE=``

# Tar files for every backup node
for backupNode in `ls -d $DIRECTORY/*/`
do
  for backupShare in `ls -d ${backupNode}*/`
    do
      if [ "$INDEX" -eq "0" ]; then
        if [ -a $REPORT ]; then
          rm $REPORT
        fi
        tar -cjvf ${backupShare}backup_${DATE}.tar.bz2 /data/clients/ > $REPORT
        FIRSTBACKUPNODE=${backupShare}backup_${DATE}.tar.bz2
        INDEX=`expr $INDEX + 1`
      else
        cp ${FIRSTBACKUPNODE} ${backupShare}backup_${DATE}.tar.bz2
      fi
    done
done